'use strict';
const db = uniCloud.database()
const $ = db.command.aggregate
exports.main = async (event, context) => {
	const {
		user_id,
		type
	} = event
	let matchObj = {}
	if(type !== 'all') {
		matchObj = {
			current: true
		}
	}
	let userinfo = await db.collection('user').doc(user_id).get()
	userinfo = userinfo.data[0]
	// label_ids =  ['label._id']
	const res = await db.collection('label')
	.aggregate()
	.addFields({
		current: $.in(['$_id',$.ifNull([userinfo.label_ids, []])])
	})
	.match(matchObj)
	.end()
	// const res = await db.collection('label').get()
	return {
		code: 200,
		msg: '数据获取成功',
		data: res.data
	}
};
